@extends('admin.main')
@section('head')
    <style>
        .tdname {
            padding-left: 4px;
            padding-right: 4px;
        }
        .tdval {
            text-align: right;
            padding-right: 4px;
            color: #404040;
        }
        .tdval1 {
            text-align: center;
            color: #aaa;
        }
        .tdval2 {
            text-align: right;
            color: #404040;
        }
        .tdmin {
            text-align: center;
        }
        .tdinput {
            text-align: right;
            background-color: lightgoldenrodyellow;
            width: 96%;
            border:0px;
            text-align: right;
            color: red;
        }
    </style>
@endsection
@section('body')
    <div class="main-title">
        <h2>{{isset($info['id']) ? '退还':'添加'}}押金</h2>
    </div>
    <div class="tab-wrap">
        <div class="tab-content">
            <form action="" method="post" class="form-horizontal">
                @if(!isset($info))
                <table border="1" cellspacing="4" cellpadding="4" width="60%">
                    <th colspan="4" style="background-color: grey;color: white">电子押金条</th>
                    <tr>
                        <td class="tdname">店铺名称</td>
                        <td colspan="3" class="tdval">{{$shop['shop_name']}}</td>
                    </tr>
                    <tr>
                        <td class="tdname">客户名称</td>
                        <td colspan="3" class="tdval">{{$member['name']}} ( ID:{{$member['id']}} )</td>
                    </tr>
                    <tr>
                        <td class="tdname">客户电话</td>
                        <td colspan="3" class="tdval">{{$member['mobile']}}</td>
                    </tr>
                    <tr>
                        <td class="tdname">客户地址</td>
                        <td colspan="3" class="tdval">{{$member['address']}}</td>
                    </tr>
                    {{--<tr>--}}
                        {{--<td class="tdname">水桶丢损赔付</td>--}}
                        {{--<td colspan="3">--}}
                            {{--<input type="text" name="lose_pay" class="tdinput" style="width: 93%;"--}}
                                   {{--value=""> <span style="color: green">元/个 </span>--}}
                        {{--</td>--}}
                    {{--</tr>--}}
                    <tr>
                        <td class="tdname">自备桶</td>
                        <td style="width: 30%;">
                            <input type="text" name="self_bucket" class="tdinput" style="width: 90%;color: red"
                                   value=""><span style="color: green;margin-left: 2px;">个 </span>
                        </td>
                        <td class="tdmin">品牌</td>
                        <td class="tdval1" style="width: 30%;">
                            <select name="self_bucket_category" id="self_bucket_category" class="tdval2" style="width: 100%">
                                @if(count($bucketData))
                                    @foreach($bucketData as $v)
                                        <option value="{{$v['bucket_category_id']}}">{{$v['category']['title']}}</option>
                                    @endforeach
                                @endif
                            </select></td>

                    </tr>
                    <tr>
                        <td class="tdname">押金桶</td>
                        <td style="width: 30%;">
                        <input type="text" name="cash_bucket" class="tdinput" style="width: 90%;color: red"
                               value=""><span style="color: green;margin-left: 2px;">个 </span>
                        </td>
                        <td class="tdmin">品牌</td>
                        <td class="tdval1" style="width: 30%;">
                            <select name="cash_bucket_category" id="cash_bucket_category" class="tdval2" style="width: 100%">
                                @if(count($bucketData))
                                    @foreach($bucketData as $v)
                                        <option value="{{$v['bucket_category_id']}}">{{$v['category']['title']}}</option>
                                    @endforeach
                                @endif
                            </select></td>
                    </tr>
                    <tr>
                        <td class="tdname">收水桶押金</td>
                        <td colspan="3">
                            <input type="text" name="cash" class="tdinput" value=""> <span style="color: green">元</span>

                        </td>
                    </tr>
                    {{--<tr>--}}
                        {{--<td class="tdname">押饮水机</td>--}}
                        {{--<td colspan="3">--}}
                            {{--<input type="text" name="water_dispenser" class="tdinput" style="color: blue" value=""><span style="color: green"> 台</span>--}}
                        {{--</td>--}}
                    {{--</tr>--}}
                    {{--<tr>--}}
                        {{--<td class="tdname">收饮水机押金</td>--}}
                        {{--<td colspan="3">--}}
                            {{--<input type="text" name="water_dispenser_cash" class="tdinput" value=""> <span style="color: green">元</span>--}}
                        {{--</td>--}}
                    {{--</tr>--}}
                    <tr>
                        <td class="tdname">备注：</td>
                        <td colspan="3">
                            <input type="text" name="description" class="tdinput" style="width: 100%;text-align: center;color: grey" value="">
                        </td>
                    </tr>
                </table>
                    @else
                    <table border="1" cellspacing="4" cellpadding="4" bgcolor="#d3d3d3" width="60%">
                        <ul style="background-color: lightskyblue">
                            <li>操作说明：水站应在取回用户处所有桶之后在进行退还押金操作</li>
                            <li>操作流程：1.配送端使用“零送水回桶”功能，取回所有水站水桶，结算押金并退还相应用户自备水桶 2.登录后台操作退还押金</li>
                        </ul>
                        <br>
                        <br>
                        <th colspan="4" style="background-color: grey;color: white">电子押金条 ( 原始凭证 ) </th>
                        <tr>
                            <td class="tdname">店铺名称</td>
                            <td colspan="3" class="tdval">{{$shop['shop_name']}}</td>
                        </tr>
                        <tr>
                            <td class="tdname">客户名称</td>
                            <td colspan="3" class="tdval">{{$member['name']}} ( ID:{{$member['id']}} )</td>
                        </tr>
                        <tr>
                            <td class="tdname">客户电话</td>
                            <td colspan="3" class="tdval">{{$member['mobile']}}</td>
                        </tr>
                        <tr>
                            <td class="tdname">客户地址</td>
                            <td colspan="3" class="tdval">{{$member['address']}}</td>
                        </tr>
                        {{--<tr>--}}
                            {{--<td class="tdname">水桶丢损赔付</td>--}}
                            {{--<td colspan="3">--}}
                                {{--<div style="float: right">--}}
                                    {{--<span style="color: red;">{{isset($info['lose_pay']) ? $info['lose_pay'] : ''}} </span><span style="color: green;margin-right: 4px;">元/个</span>--}}
                                {{--</div>--}}

                            {{--</td>--}}
                        {{--</tr>--}}
                        <tr>
                            <td class="tdname">自备桶</td>
                            <td style="width: 30%;">
                                <div style="float: right">
                                    <span style="color: blue;">{{isset($info['self_bucket']) ? $info['self_bucket'] : ''}} </span><span style="color: green;margin-right: 4px;">个</span>
                                </div>
                            </td>
                            <td class="tdmin">品牌</td>
                            <td class="tdval1" >
                                @if(count($bucketData))
                                    @foreach($bucketData as $v)
                                        @if(isset($info) && $info['self_bucket_category'] == $v['bucket_category_id'])
                                            <span style="color: #404040">{{$v['category']['title']}}</span>
                                        @endif
                                    @endforeach
                                @endif
                            </td>
                        </tr>
                        <tr>
                            <td class="tdname">押金桶</td>
                            <td style="width: 30%;">
                                <div style="float: right">
                                    <span style="color: blue;">{{isset($info['cash_bucket']) ? $info['cash_bucket'] : ''}} </span><span style="color: green;margin-right: 4px;">个</span>
                                </div>
                            </td>
                            <td class="tdmin">品牌</td>
                            <td class="tdval1" >
                                @if(count($bucketData))
                                    @foreach($bucketData as $v)
                                        @if(isset($info) && $info['cash_bucket'] == $v['bucket_category_id'])
                                            <span style="color: #404040">{{$v['category']['title']}}</span>
                                        @endif
                                    @endforeach
                                @endif
                            </td>
                        </tr>
                        {{--<tr>--}}
                            {{--<td class="tdname">应回桶</td>--}}
                            {{--<td colspan="3" class="tdval"><span style="color: blue">--}}
                                    {{--{{ $member['initial_bucket_num'] +  $member['self_bucket_num']+ $member['total_bucket_num'] - $member['total_back_bucket_num'] - $member['self_bucket_num']}}--}}
                                {{--</span> <span style="color: green;">个</span></td>--}}
                        {{--</tr>--}}
                        {{--<tr>--}}
                            {{--<td class="tdname">应收饮水机</td>--}}
                            {{--<td colspan="3" class="tdval"><span style="color: blue">{{$info['water_dispenser']}}</span> <span style="color: green;">台</span></td>--}}
                        {{--</tr>--}}
                        <tr>
                            <td class="tdname">收水桶押金</td>
                            <td colspan="3" class="tdval"><span style="color: red">{{$info['cash']}}</span> <span style="color: green;">元</span></td>
                        </tr>
                        {{--<tr>--}}
                            {{--<td class="tdname">应退饮水机押金</td>--}}
                            {{--<td colspan="3" class="tdval"><span style="color: red">{{$info['water_dispenser_cash']}}</span> <span style="color: green;">元</span></td>--}}
                        {{--</tr>--}}
                        <tr>
                            <td class="tdname">备注：</td>
                            <td colspan="3" class="tdval2" style="text-align: center">
                                <span >{{$info['description']}}</span>
                            </td>
                        </tr>
                        <tr></tr>
                    </table>
                    <table border="1" cellspacing="4" cellpadding="4" width="60%">
                        <th colspan="4" style="background-color: orange;">退还押金</th>
                        <tr>
                            <td class="tdname">实退自备桶</td>
                            <td >
                                <input type="text" name="back_self_bucket_num" class="tdinput" style="width: 90%;color: blue"
                                       value=""><span style="color: green;margin-left: 2px;">个 </span>
                            </td>
                            <td class="tdmin">品牌</td>
                            <td >
                                <select name="back_self_bucket_category" id="back_self_bucket_category" class="tdval2" style="width: 100%">
                                    @if(count($bucketData))
                                        @foreach($bucketData as $v)
                                            <option value="{{$v['bucket_category_id']}}">{{$v['category']['title']}}</option>
                                        @endforeach
                                    @endif
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="tdname">实退押金桶</td>
                            <td >
                                <input type="text" name="back_cash_bucket_num" class="tdinput" style="width: 90%;color: blue"
                                       value=""><span style="color: green;margin-left: 2px;">个 </span>
                            </td>
                            <td class="tdmin">品牌</td>
                            <td >
                                <select name="back_cash_bucket_category" id="back_cash_bucket_category" class="tdval2" style="width: 100%">
                                    @if(count($bucketData))
                                        @foreach($bucketData as $v)
                                            <option value="{{$v['bucket_category_id']}}">{{$v['category']['title']}}</option>
                                        @endforeach
                                    @endif
                                </select>
                            </td>
                        </tr>
                        {{--<tr>--}}
                            {{--<td class="tdname">实回桶</td>--}}
                            {{--<td colspan="3">--}}
                                {{--<input type="text" name="back_bucket_num" class="tdinput" style="color: blue"--}}
                                       {{--value="">  <span style="color: green;margin-right: 4px;float: right">个</span>--}}
                            {{--</td>--}}
                        {{--</tr>--}}

                        {{--<tr>--}}
                            {{--<td class="tdname">实收饮水机</td>--}}
                            {{--<td colspan="3">--}}
                                {{--<input type="text" name="back_water_dispenser_num" class="tdinput" style="color: blue"--}}
                                       {{--value="">  <span style="color: green;margin-right: 4px;float: right">台</span>--}}
                            {{--</td>--}}
                        {{--</tr>--}}
                        <tr>
                            <td class="tdname">实退水桶押金</td>
                            <td colspan="3">
                                <input type="text" name="back_bucket_money" class="tdinput"
                                       value=""> <span style="color: green;margin-right: 4px;float: right">元</span>
                            </td>
                        </tr>
                        {{--<tr>--}}
                            {{--<td class="tdname">实退饮水机押金</td>--}}
                            {{--<td colspan="3">--}}
                                {{--<input type="text" name="back_water_dispenser_money" class="tdinput"--}}
                                       {{--value=""> <span style="color: green;margin-right: 4px;float: right">元</span>--}}
                            {{--</td>--}}
                        {{--</tr>--}}
                        <tr>
                            <td class="tdname">备注：</td>
                            <td colspan="3">
                                <input type="text" name="back_description" class="tdinput" style="width: 100%;text-align: center;color: grey" value="">
                            </td>
                        </tr>
                    </table>
                @endif
                <div style="height: 50px;"></div>
                @if(isset($info['id']) && !$num)
                    <div>
                        <span style="color: red;font-weight: bold;font-size: 16px">注意： 此押金条为该用户最后一张押金条，请认真核实最终退还数据，一旦退还则表示该用户与水站之间清算完毕，用户押金、水桶和水票信息将全部清零！</span>
                    </div>
                @endif
                <br>
                <div class="form-item" style="clear: both">
                    <input type="hidden" name="id" value="{{isset($info['id']) ? $info['id'] : ''}}">
                    <input type="hidden" name="mid" value="{{$member['id']}}">
                    <input type="hidden" name="shop_id" value="{{$member['shop_id']}}">
                    <input type="hidden" name="admin_id" value="{{$member['admin_id']}}">
                    <button type="submit" id="submit" class="btn submit-btn ajax-post" target-form="form-horizontal">
                        @if(!isset($info))保 存@else退 还@endif
                    </button>
                    <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
                </div>
            </form>
        </div>
    </div>
@endsection

@section('script')
    <script>
        var categoryData = JSON.parse('{!! json_encode($bucketData) !!}');
        var self_bucket_category = parseInt('{{isset($info) ? $info['self_bucket_category'] : 0}}}');
        var cash_bucket_category = parseInt('{{isset($info) ? $info['cash_bucket_category'] : 0}}}');
        $(window).ready(function () {
            var shop_id = $('#shop_id').val();
            changeOptions(categoryData, shop_id, 'self_bucket_category', self_bucket_category)
            changeOptions(categoryData, shop_id, 'cash_bucket_category', cash_bucket_category)
        });
        function changeOptions(categoryData, shop_id, target, category_id) {
            var options = '';
            for (var i in categoryData) {
                if (categoryData[i].shop_id == shop_id) {
                    if (category_id == categoryData[i].id) {
                        options += "<option value='" + categoryData[i].id + "' selected>" + categoryData[i].category.title + "</option>";
                    } else {
                        options += "<option value='" + categoryData[i].id + "'>" + categoryData[i].category.title + "</option>";
                    }
                }
            }
            $("#" + target).append(options);
        }
        $('#shop_id').change(function () {
            var shop_id = $(this).val();
            $("#self_bucket_category").empty();
            $("#cash_bucket_category").empty();
            changeOptions(categoryData, shop_id, 'self_bucket_category', 0)
            changeOptions(categoryData, shop_id, 'cash_bucket_category', 0)
        });
    </script>
@endsection
